package com.hncic.tx.center.common.util;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
/**
 * @author smj E-mail: 463136320@qq.com
 * @created 2017年8月18日 下午12:45:15
 * @since jdk1.8
 * @version 1.0
 * @describe
 */

public class UtilJson {
	protected Logger logger = LoggerFactory.getLogger(getClass());
	public static final ObjectMapper mapper0 = newObjectMapper0();

	private static ObjectMapper newObjectMapper0() {
		ObjectMapper result = new ObjectMapper();
		result.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
		result.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
		result.setSerializationInclusion(Include.NON_NULL);
		result.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); // 不输出value=null的属性
		result.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // 不知道的属性，不异常
		result.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));
		result.setDateFormat(new SimpleDateFormat(UtilDate.defaultPattern0));
		return result;
	}

	public static String writeValueAsString(Object value) {
		try {
			return mapper0.writeValueAsString(value);
		} catch (IOException e) {
			throw new IllegalArgumentException(e);
		}
	}

}


